// 设置cookie
let setCookie = function (name, value) {
  document.cookie = name + '=' + escape(value) + ';path=/'
}
// 获取cookie
let getCookie = function (name) {
  let reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
  let arr = document.cookie.match(reg)
  if (arr) {
    return unescape(arr[2])
  } else {
    return null
  }
}
// 清除cookie
let delCookie = function (name) {
  let exp = new Date()
  exp.setTime(exp.getTime() - 1)
  let cval = getCookie(name)
  if (cval !== null) {
    document.cookie = name + '=' + cval + ';path=/' + ';expires=' + exp.toGMTString()
  }
}
// 查找数组中是否包含
let contains = function (arr, obj) {
  var i = arr.length
  while (i--) {
    if (arr[i] === obj) {
      return true
    }
  }
  return false
}

export {
  setCookie,
  getCookie,
  delCookie,
  contains
}
